<template>
    <el-container class="containerbox">
        <el-header>
            <div>
                <img src="../assets/img/logo.gif" alt="">
                <span>电商系统</span>
            </div>
            <el-button type="info"  @click="offbtn">退出</el-button>
        </el-header>
        <el-container>
            <!-- 侧边栏 -->
            <!-- 动态给侧边栏设置宽度 -->
            <el-aside :width="isCollapse ? '64px' : '200px' ">
                <div class="toggle" @click="togglebtn">|||</div>
                <!-- 选择框 -->
                 <!-- 选中的值高亮  :default-active="activePath"-->
                <el-menu
                    unique-opened
                    :collapse='isCollapse'
                    :collapse-transition="false"
                    background-color="#545c64"
                    text-color="#fff"
                    active-text-color="#409EFF"
                    :router='true'
                    :default-active="activePath"
                    >
                    <!-- 一级菜单 -->
                    <el-submenu :index="item.id + ''" v-for="item in menulist" :key='item.id'  >
                        <!--template是 模板 -->
                        <template slot="title">
                            <!-- i是图标 -->
                        <i class="el-icon-location"></i>
                        <!-- span是文本区域 -->
                        <span>{{item.name}}</span>
                        </template>

                        <!-- 二级区域 -->

                       <el-menu-item :index="item.id + ''" v-for="item in item.clist" :key='item.id' @click="saveNavState(item.id + '')">
                            <!--template是 模板 -->
                            <template slot="title">
                                <!-- i是图标 -->
                                <i class="el-icon-menu"></i>
                                <!-- span是文本区域 -->
                                <span>{{item.name}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>

                    </el-menu>
            </el-aside>
            <!-- 中间部分a-->
            <el-main>
              <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>

</template>
<script>
export default ({
  data () {
    return {
      menulist: [
        {
          id: 1,
          name: '用户管理',
          clist: [
            {
              id: 11,
              name: '用户列表'
            }
          ]
        },
        {
          id: 2,
          name: '权限管理',
          clist: [
            {
              id: 21,
              name: '角色列表'
            },
            {
              id: 22,
              name: '权限列表'
            }
          ]
        },
        {
          id: 3,
          name: '商品管理',
          clist: [
            {
              id: 31,
              name: '角色列表'
            },
            {
              id: 32,
              name: '权限列表'
            }
          ]
        },
        {
          id: 4,
          name: '订单管理',
          clist: [
            {
              id: 41,
              name: '角色列表'
            },
            {
              id: 42,
              name: '权限列表'
            }
          ]
        },
        {
          id: 5,
          name: '商品管理',
          clist: [
            {
              id: 51,
              name: '角色列表'
            },
            {
              id: 52,
              name: '权限列表'
            }
          ]
        }
      ],
      isCollapse: false,
      activePath: ' '
    }
  },
  created () {
    this.activePath = window.sessionStorage.getItem('active')
  },
  methods: {
    offbtn () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 点击按钮，折叠左边菜单
    togglebtn () {
      console.log(123)
      if (!this.isCollapse) {
        this.isCollapse = true
      } else {
        this.isCollapse = false
      }
    },
    // 设置被选中的颜色
    saveNavState (nav) {
      console.log(nav)
      window.sessionStorage.setItem('active', nav)
      this.activePath = nav
    }
  }
})
</script>
<style scoped>
.containerbox{
    height: 100%;
}
.el-header{
    background:#373D41;
    display: flex;
    justify-content: space-between;
}
.el-header div{
    display: flex;
    align-items: center;
    height: 100%;
}
.el-header div img{
    width:50px;
    /* margin-top:15%; */
    border-radius: 50%;
}
.el-header div span{
    line-height: 200%;
    font-size: 20px;
    color:#fff;
    margin-left: 10px;

}
.el-aside{
    background:#333744;
    border: none;
    overflow: hidden;
}
.el-main{
    background:#eaedf1;
}
.toggle{
    background: #4a5064;
    font-size: 10px;
    line-height:24px;
    color:#fff;
    text-align:center;
    letter-spacing: 0.2em;
    cursor: pointer;
}
</style>
